Micron Document
Fox's Git Mirrors

Node / RFnexus / code.git / commits / d4bab41

Commit d4bab41d1553fb3cc969b91c6bb2d95e577771f1


Parents : 51a56dc
Author : Ahmet Inan <inan@aicodix.de>
Date : 2025-06-14T09:16:31+02:00

added XorShiftMask

Changes

1 files changed, 31 insertions(+), 0 deletions(-)


Diff

diff --git a/xorshift.hh b/xorshift.hh
index 8b74f60..3dfed83 100644
--- a/xorshift.hh
+++ b/xorshift.hh
@@ -8,6 +8,37 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
namespace CODE {
+template <typename TYPE, int BITS, int FIRST, int SECOND, int THIRD, int SEED = 1>
+class XorShiftMask
+{
+ static const TYPE mask = (1 << BITS) - 1;
+ TYPE y_;
+public:
+ typedef TYPE result_type;
+ static constexpr result_type min()
+ {
+ return 1;
+ }
+ static constexpr result_type max()
+ {
+ return mask;
+ }
+ XorShiftMask(TYPE y = SEED) : y_(y) {}
+ void reset(TYPE y = SEED)
+ {
+ y_ = y;
+ }
+ TYPE operator()()
+ {
+ y_ ^= y_ << FIRST;
+ y_ &= mask;
+ y_ ^= y_ >> SECOND;
+ y_ ^= y_ << THIRD;
+ y_ &= mask;
+ return y_;
+ }
+};
+
class Xorshift32
{
static const uint32_t Y = 2463534242;

Served by rngit 1.4.1 - Generated in 0.02s